package com.bawei.mall.user.utils;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;


@Component
public class Addr {

    static String host = "https://jmkddzjx.market.alicloudapi.com";
    static String path = "/express/address-parse";
    static String method = "POST";
    static String appcode = "96635bcced95420eba6aa48d3e0ce083"; // 替换为你的实际 AppCode

    public String  analyzeAddres(String str) {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + appcode);
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        bodys.put("address", str);

        try {
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            System.out.println(response.toString());
            // 如果需要获取response的body，可以使用下面的方法
            // System.out.println(EntityUtils.toString(response.getEntity()));
            String string = EntityUtils.toString(response.getEntity());
            return string;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}